#include <bits/stdc++.h>
#define gc getchar
#define pc putchar
#define pt printf
#define IL inline
#define int long long
using namespace std;
const int Mxn=1e5+5;
int N,Ans,Fir,Sec;
IL int _() {
	int x=0,f=0;char ch=gc();
	while(ch<'0'||ch>'9') f|=(ch=='-'),ch=gc();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=gc();
	return f?-x:x;
}
IL void __(int x) {
	int stk[30],tp=0;
	if(x<0) x=-x,pc('-');
	do stk[++tp]=x%10,x/=10;while(x);
	while(tp) pc(stk[tp--]^48);
}
#define A(x) P[x].a
#define B(x) P[x].b
#define S(x) (P[x].a+P[x].b)
int Max(int x,int y) {return x>y?x:y;}
int Min(int x,int y) {return x<y?x:y;}
struct DATA{
	int a,b,s;
	bool operator <(const DATA &A) const{return b>A.b;}
}P[Mxn];
signed main() {
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	N=_();
	for(int i=1;i<=N;++i) P[i]=(DATA){_(),_()};
	sort(P+1,P+1+N),Ans=S(1)+S(2)+S(3);
	Fir=Min(S(1),S(2)),Sec=Max(S(1),S(2));
	for(int i=3;i<=N;++i) {
		Ans=Min(Ans,A(i)+Fir+Sec);
		if(S(i)<Fir) Sec=Fir,Fir=S(i);
		else if(S(i)<Sec) Sec=S(i); 
	}
	__(Ans);
	return 0;
}
